<?php
/**
 * Created by LíJimpéy(：
 * User: jimpey88
 * Date: 2024/3/26
 * Email: < jimpey@qq.com >
 * Project: company-admin-tp6
 */

namespace app\backend_api\controller;

use app\backend_api\services\JwtTokenService;
use app\backend_api\services\LoginService;
use app\backend_api\validate\LoginValidate;
use app\BaseController;
use app\common\Utils\IpInfoUtils;
use think\facade\Cache;

class Login extends BaseController
{

    public function testToken()
    {
        $token = input('token', '');
        dd(JwtTokenService::checkToken($token)['data']->uid);
    }
    public function index()
    {
        // 参数检验
        $params = (new LoginValidate())->post()->goCheck();
        // 验证码校验
        $this->app->make('app\\common\\Utils\\Captcha')
            ->check($params['image_captcha'], $params['image_key']);

        unset($params['image_captcha'], $params['image_key']);

        return $this->success((new LoginService())->login($params));
    }

    public function user(LoginService $loginService): \think\response\Json
    {
        return $this->success($loginService::getAdminInfo());
    }

    public function logout()
    {
        Cache::store('redis')->delete('admin_id_'.request()->admin_id);
        return $this->successMsg('退出成功');
    }

}
